VERSION 1.0 CLASS
BEGIN
  MultiUse = -1  'True
  Persistable = 0  'NotPersistable
  DataBindingBehavior = 0  'vbNone
  DataSourceBehavior  = 0  'vbNone
  MTSTransactionMode  = 0  'NotAnMTSObject
END
Attribute VB_Name = "clsFundExists"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = True
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = True
Option Explicit

Public Function FundExists(ByVal sUserName, ByVal nFundNumber) As Boolean

    Dim cnFundExists As ADODB.Connection
    Dim rsCount As ADODB.Recordset
    Dim rsFundExists As ADODB.Recordset
    Dim cmd1 As ADODB.Command
    Dim cmd2 As ADODB.Command
    
    
    
    Set cnFundExists = New ADODB.Connection
    
    Set cmd1 = New ADODB.Command
    Set cmd2 = New ADODB.Command
    Set rsCount = New ADODB.Recordset
    Set rsFundExists = New ADODB.Recordset
    Dim SQL1 As String
    Dim SQL2 As String
    Dim nNumberOfFundsExist As String
    Dim blFundExists As Boolean
    
    
    On Error GoTo PROC_ERROR
   
    With cnFundExists
        .ConnectionString = GetConnectionString() 'Johann (20090625): Centralised code for connection string added
        .Open
    End With
    
    'Count how many records exist for the same fund number
    SQL1 = "select Count(*) NumberOfFundsExist from dir_funds where fund_number = " & nFundNumber

    Set cmd1 = New ADODB.Command
    Set cmd1.ActiveConnection = cnFundExists
    
    cmd1.CommandType = adCmdText
    cmd1.CommandText = SQL1
    
    Set rsCount = cmd1.Execute
    nNumberOfFundsExist = rsCount.Fields("NumberOfFundsExist").Value
    
    If nNumberOfFundsExist > 1 Then
        
        'Get the fund ID. This ID will be used to determine which one of the fund number contact details to update.
        SQL2 = "select fun_id from dir_funds where fund_number = '" & nFundNumber & "' and scod_fund_type = '" & sFundType & "'"

        Set cmd2 = New ADODB.Command
        Set cmd2.ActiveConnection = cnFundExists
        
        cmd2.CommandType = adCmdText
        cmd2.CommandText = SQL2
        
        
        ' Perform the query
        Set rsFundExists = cmd2.Execute
        
        If Not rsFundExists.EOF Then
            FundExists = True
            nFundID = rsFundExists.Fields("fun_id").Value
        Else
            FundExists = False
        End If
        
        'cleanup
        rsFundExists.Close
        Set rsFundExists = Nothing
        rsCount.Close
        Set rsCount = Nothing
    
        cnFundExists.Close
        Set cnFundExists = Nothing
    Else
        Dim dllFundExists As Object
        Set dllFundExists = CreateObject("keytax.clsFunds")
        blFundExists = dllFundExists.FundExists(strUser, nFundNumber)
        If blFundExists = True Then
            FundExists = True
        Else
            FundExists = False
        End If
        
        'cleanup
        rsCount.Close
        Set rsCount = Nothing
    
    End If
    
   
PROC_EXIT:
  Exit Function

PROC_ERROR:
  FundExists = False
  Err.Raise Err.Number, _
            "clsFundExists/FundExists", _
            Err.Description
            
Resume PROC_EXIT

End Function
